package dcl.software.filesync.server.auth;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.bson.Document;
import org.bson.types.Binary;

import dcl.software.filesync.server.BaseDomain;

@org.springframework.data.mongodb.core.mapping.Document(collection = "users")
public class User extends BaseDomain {
	private String _id;
	private String password;
	private byte[] salt;
	private String email;
	private String directory;

	public User(Document doc) {
		_id = doc.getString("_id");
		password = doc.getString("password");
		salt = ((Binary) doc.get("salt")).getData();
		email = doc.getString("email");
	}

	public User() {
	}

	public User(UserDTO createDTO) {
		_id = createDTO.getUserName();
		password = createDTO.getPassword();
		email = createDTO.getEmail();
	}

	public String getUserName() {
		return _id;
	}

	public void setUserName(String userName) {
		this._id = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public byte[] getSalt() {
		return salt;
	}

	public void setSalt(byte[] salt) {
		this.salt = salt;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getDirectory() {
		return _id;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}

	@Override
	public boolean equals(Object o) {
		return EqualsBuilder.reflectionEquals(this, o);
	}
}
